Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Namespace BMLERP
	Friend Class frmORD560
		Inherits System.Windows.Forms.Form
		Dim INVType(3) As Object
		Dim StaOrd(7) As Object
		Dim Per(3) As Object
		Dim OldEHODN As String
		Dim NewTrans As Byte
		Dim OldCurRate As Double
		Dim WithEvents RecOrd As ADODB.Recordset
		Dim SQL As String
		Private Sub UpdateAmt()
			Dim txtELPC As Object
			Dim DiscAMT, DiscBAM As Object
			Dim Nonvalue As Object

			On Error Resume Next
			Select Case cboELPER.SelectedIndex + 1
				Case 1
					Nonvalue = IsNothing(txtELQTY.Text) And IsNothing(txtELPRC.Text) And IsNothing(txtELPC)
					If Not Nonvalue Then
						txtELBCA.Text = CStr(Val(txtELQTY.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)))
						txtELBVA.Text = CStr(Val(txtELBCA.Text) * Val(txtELVAT.Text))

						txtELAMT.Text = CStr(CInt(Val(txtELQTY.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)) * Val(txtEHCER.Text)))
						txtELVAM.Text = CStr(CInt(Val(txtELAMT.Text) * Val(txtELVAT.Text)))
					Else
						MsgBox("Check data again")
					End If

				Case 2
					Nonvalue = IsNothing(txtELWGT.Text) And IsNothing(txtELPRC.Text) And IsNothing(txtELPC)
					If Not Nonvalue Then
						txtELBCA.Text = CStr(Val(txtELWGT.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)))
						txtELBVA.Text = CStr(Val(txtELBCA.Text) * Val(txtELVAT.Text))

						txtELAMT.Text = CStr(CInt(Val(txtELWGT.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)) * Val(txtEHCER.Text))) '+ Val(txtELVAM))
						txtELVAM.Text = CStr(CInt(Val(txtELAMT.Text) * Val(txtELVAT.Text)))
					Else
						MsgBox("Check data again")
					End If
			End Select
			'txtELVAT.SetFocus
		End Sub
		Private Sub cboEHCCD_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHCCD.ClickEvent
			Dim RecCCI As ADODB.Recordset
			If eventArgs.area = 2 Then
				txtEHCCD.Text = cboEHCCD.CtlText
				cboEHCCD.Visible = False
				RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtEHCCD.Text & "' order by CIDTE DESC")
				If Not RecCCI.EOF Then
					txtEHCER.Text = RecCCI.Fields("CICCR").Value
				Else
					txtEHCER.Text = CStr(0)
				End If
			End If
		End Sub

		Private Sub cboEHCNO_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHCNO.ClickEvent
			If eventArgs.area = 2 Then
				txtEHCNO.Text = cboEHCNO.BoundText
				txtCMNME.Text = cboEHCNO.CtlText
				cboEHCNO.Visible = False
				txtEHSNO.Focus()
			End If
		End Sub


		Private Sub cboEHITP_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboEHITP.SelectedIndexChanged
			'    txtEHODN.SetFocus
		End Sub

		Private Sub cboEHSNO_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHSNO.ClickEvent
			If eventArgs.area = 2 Then
				txtEHSNO.Text = cboEHSNO.BoundText
				txtMMNME.Text = cboEHSNO.CtlText
				cboEHSNO.Visible = False
				txtEHSTN.Focus()
			End If
		End Sub

		Private Sub cboEHSTT_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboEHSTT.SelectedIndexChanged
			'MsgBox Left(cboEHSTT.List(cboEHSTT.ListIndex), 1)
		End Sub

		Private Sub cboELITN_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboELITN.ClickEvent
			If eventArgs.area = 2 Then
				txtELITN.Text = cboELITN.BoundText
				txtELPRC.Text = Find("IIM", "IMPRC", "WHERE IMITN='" & txtELITN.Text & "'")

				txtELITD.Text = Find("IIM", "IMITD", " WHERE IMITN='" & txtELITN.Text & "'")

				cboELITN.Visible = False
				txtELVAT.Text = VATRate(txtEHCNO, txtELITN)
				txtELQTY.Focus()
			End If
		End Sub

		Private Sub cboELPER_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboELPER.SelectedIndexChanged
			Call UpdateAmt()
		End Sub


		Private Sub cmdAddnew_Click()
			NewTrans = True
			ISADDING = True
			ISEDITING = True
			WriteToScreen()
			ButtonStatus()
			txtEHODN.Focus()
		End Sub

		Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
			NewTrans = False
			ISADDING = False
			ISEDITING = False
			WriteToScreen()
			ButtonStatus()
		End Sub

		Private Sub cmddelline_Click()
			If txtEHODN.Text <> "" And txtELITN.Text <> "" Then
				SQL = ""
				SQL = "SELECT     dbo.ECH.EHODN, dbo.ECL.ELITN " & "FROM   dbo.ECH INNER JOIN dbo.ECL ON dbo.ECH.EHODN = dbo.ECL.ELODN " & "WHERE     (dbo.ECH.EHSTT = '1') AND (dbo.ECL.ELSTT = '1') AND (dbo.ECH.EHODN = '" & Trim(txtEHODN.Text) & "')"
				RecOrd = New ADODB.Recordset
				RecOrd.Open(SQL, ConnectString, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
				If RecOrd.RecordCount > 0 Then
					SQL = ""
					SQL = "delete from ECL where ELITN='" & Trim(txtELITN.Text) & "'"
					If MsgBox(" Do you want delete this line ?", MsgBoxStyle.DefaultButton2 + MsgBoxStyle.OkCancel + MsgBoxStyle.Critical, "Deleting...") = MsgBoxResult.Ok Then
						DBconn.Execute(SQL)
						WriteToScreen()
					Else
						Exit Sub
					End If
				Else
					MsgBox("Can not delete this line !", MsgBoxStyle.Critical, "Warning")
					Exit Sub
				End If
			Else
				MsgBox("The TextBox OrderNo or ItemNo is Empty...!", MsgBoxStyle.Critical, "Warning")
			End If
		End Sub

		Private Sub cmdEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEdit.Click
			ISEDITING = True
			'WriteToScreen
			ButtonStatus()
		End Sub

		Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			Me.Close()
		End Sub

		Private Sub cmdNewItem_Click()
			'NewTrans = True
			If txtEHODN.Text <> "" Then
				ISADDING = True
				ISEDITING = True
				WriteToScreen()
				ButtonStatus()
			End If
		End Sub

		Private Sub CmdPreInvoice_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdPreInvoice.Click
			CrystalReport2.ReportFileName = DDAN & "\Ord560.rpt"
			CrystalReport2.RetrieveStoredProcParams()
			CrystalReport2.set_StoredProcParam(0, txtEHODN.Text)
			CrystalReport2.Destination = Crystal.DestinationConstants.crptToWindow
			CrystalReport2.Action = 1
		End Sub

		Private Sub cmdReview_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReview.Click
			'Dim myform As New frmReview
			'myform.Tag = "ORD500"
			'myform.Show()
			frmReview.Tag = "ORD500"
			frmReview.ShowDialog()
			ISEDITING = False
			ISADDING = False
			If frmReview.Tag <> "" Then
				txtEHODN.Text = frmReview.Tag
				frmReview.Close()
				'If myform.Tag <> "" Then
				'txtEHODN.Text = myform.Tag
				'myform.Close()
				txtELOLN.Text = CStr(1)
				WriteToScreen()
				cmdEdit.Enabled = True
			End If
		End Sub
		Sub WriteToScreen()
			Dim i As Object
			Dim StrCV As Object
			Dim txtEHBAM As Object
			Dim recECL As ADODB.Recordset
			If NewTrans Then
				cboEHITP.SelectedIndex = 0
				txtEHODN.Text = ""
				txtEHDTE.Text = VB6.Format(WorkingDate, "dd/mm/yyyy")
				txtEHCNO.Text = ""
				txtEHNOL.Text = CStr(0)
				txtCMNME.Text = ""
				txtEHCPO.Text = ""
				txtEHPTC.Text = ""
				cboEHSTT.SelectedIndex = 0
				cboEHCCD.defText = ""
				txtEHCCD.Text = ""
				txtEHCER.Text = CStr(0)
				txtEHAMT.Text = CStr(0)
				txtEHVAM.Text = CStr(0)
				txtEHBAM = 0
				txtEHBVA.Text = CStr(0)
				txtEHSNO.Text = ""
				txtMMNME.Text = ""
				cboEHSNO.defText = ""
				txtEHDUE.Text = ""
				txtEHSTN.Text = ""
				txtEHSTA.Text = ""

			End If

			If ISADDING Then
				txtELITN.Text = ""
				txtELITD.Text = ""
				txtELOLN.Text = CStr(0)
				txtELQTY.Text = CStr(0)
				txtELPSQ.Text = CStr(0)
				txtELWGT.Text = CStr(0)
				txtELPSW.Text = CStr(0)
				txtELPRC.Text = CStr(0)
				cboELPER.Text = ""
				txtELPDC.Text = CStr(0)
				txtELAMT.Text = CStr(0)	' Line amount
				txtELVAM.Text = CStr(0)	' VAT line (VND)
				txtELBCA.Text = CStr(0)	' Base currency line amount
				txtELBVA.Text = CStr(0)	' VAT base currency
				txtELVAT.Text = CStr(0)
				cboELSTT.SelectedIndex = 0
				StrCV = ""
			Else

				'FROM AVM LEFT JOIN IIM ON AVM.VMVDN = IIM.IMVDC
				recECL = DBconn.Execute("select ECH.* from ECH where ECH.EHODN='" & txtEHODN.Text & "'")
				If Not recECL.EOF Then
					With recECL
						For i = 0 To cboEHITP.Items.Count - 1
							If VB.Left(VB6.GetItemString(cboEHITP, i), 1) = .Fields("EHITP").Value Then
								cboEHITP.SelectedIndex = i
								Exit For
							End If
						Next i
						'cboEHITP = INVType(!EHITP)
						txtEHNOL.Text = IIf(IsDBNull(.Fields("EHNOL").Value), 0, .Fields("EHNOL").Value)
						txtEHODN.Text = .Fields("EHODN").Value
						OldEHODN = txtEHODN.Text
						txtEHDTE.Text = VB6.Format(.Fields("EHDTE").Value, "dd/mm/yyyy")
						txtEHCNO.Text = .Fields("EHCNO").Value
						txtEHSTN.Text = .Fields("EHSTN").Value
						txtEHSTA.Text = .Fields("EHSTA").Value
						txtCMNME.Text = Find("RCM", "CMNME", " WHERE CMCNO='" & txtEHCNO.Text & "'")

						txtEHCPO.Text = IIf(IsDBNull(.Fields("EHCPO").Value), 0, .Fields("EHCPO").Value)
						txtEHPTC.Text = IIf(IsDBNull(.Fields("EHPTC").Value), "", .Fields("EHPTC").Value)
						For i = 0 To cboEHSTT.Items.Count - 1
							If VB.Left(VB6.GetItemString(cboEHSTT, i), 1) = .Fields("EHSTT").Value Then
								cboEHSTT.SelectedIndex = i
								Exit For
							End If
						Next i
						'cboEHSTT = StaOrd(!EHSTT)
						cboEHCCD.defText = .Fields("EHCCD").Value
						txtEHCER.Text = .Fields("EHCER").Value
						OldCurRate = CDbl(txtEHCER.Text)
						'txtEHORD = !EHORD
						txtEHCCD.Text = .Fields("EHCCD").Value
						txtEHAMT.Text = .Fields("EHAMT").Value
						txtEHVAM.Text = .Fields("EHVAM").Value
						txtEHBCA.Text = .Fields("EHBAM").Value
						txtEHBVA.Text = .Fields("EHBVA").Value
						txtEHSNO.Text = .Fields("EHSNO").Value
						txtMMNME.Text = Find("SMM", "MMNME", " WHERE MMSNO='" & txtEHSNO.Text & "'")
						txtEHDUE.Text = VB6.Format(.Fields("EHDUE").Value, "dd/mm/yyyy")

						.Close()
					End With
				End If

				If txtELOLN.Text <> "" Then
					recECL = DBconn.Execute("select ECL.* from ECL where ECL.ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
					If Not recECL.EOF Then
						With recECL
							txtELITN.Text = .Fields("ELITN").Value
							txtELITD.Text = .Fields("ELITD").Value
							txtELOLN.Text = .Fields("ELOLN").Value
							txtELQTY.Text = .Fields("ELQTY").Value
							txtELPSQ.Text = IIf(IsDBNull(.Fields("ELPSQ").Value), 0, .Fields("ELPSQ").Value)
							txtELWGT.Text = .Fields("ELWGT").Value
							txtELPSW.Text = IIf(IsDBNull(.Fields("ELPSW").Value), 0, .Fields("ELPSW").Value)
							txtELPRC.Text = .Fields("ELPRC").Value
							'cboELPER = Per(!ELPER)
							For i = 0 To cboELPER.Items.Count - 1
								If VB.Left(VB6.GetItemString(cboELPER, i), 1) = .Fields("ELPER").Value Then
									cboELPER.SelectedIndex = i
									Exit For
								End If
							Next i
							txtELPDC.Text = .Fields("ELPDC").Value
							txtELAMT.Text = .Fields("ELAMT").Value ' Line amount
							txtELVAM.Text = .Fields("ELVAM").Value ' VAT line (VND)
							txtELBCA.Text = .Fields("ELBCA").Value ' Base currency line amount
							txtELBVA.Text = .Fields("ELBVA").Value ' VAT base currency
							txtELVAT.Text = .Fields("ELVAT").Value
							'cboELSTT = StaOrd(!ELSTT)
							For i = 0 To cboELSTT.Items.Count - 1
								If VB.Left(VB6.GetItemString(cboELSTT, i), 1) = .Fields("ELSTT").Value Then
									cboELSTT.SelectedIndex = i
									Exit For
								End If
							Next i
							'cboELSTT.ListIndex = Val(!ELSTT) - 1
							.Close()
						End With
					End If
				End If
			End If


			Adodc3.RecordSource = "Select IMITN , IMITN +'  '+ IMITD  as IMITD FROM IIM where IMRID<>'IZ'"
			Adodc3.Refresh()


			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' ORDER BY ELOLN"
			Adodc4.Refresh()

		End Sub

		Private Sub CmdReviewOrd_Click()
			Dim myform As New frmReview
			myform.Tag = "ORD560"
			myform.Show()
			'frmReview.Tag = "ORD560"
			'frmReview/.ShowDialog()
			ISEDITING = False
			ISADDING = False

			'If frmReview.Tag <> "" Then
			'txtEHODN.Text = frmReview.Tag
			'frmReview.Close()
			If myform.Tag <> "" Then
				txtEHODN.Text = myform.Tag
				myform.Close()
				txtELOLN.Text = CStr(1)
				WriteToScreen()
				cmdEdit.Enabled = True
				CmdPreInvoice.Enabled = True
			End If
		End Sub

		Private Sub cmdSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.Click

			WriteToFile()

		End Sub
		Private Sub frmORD560_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
			NewTrans = False
			ISEDITING = False
			ISADDING = False
			OpenFile()
			ButtonStatus()
			cmdEdit.Enabled = False
			VB6_AddADODataBinding()
			cboEHCNO.RowSource = ADOBind_Adodc1.DataSource
			cboEHSNO.RowSource = ADOBind_Adodc7.DataSource
			cboEHCCD.RowSource = ADOBind_Adodc5.DataSource
			cboELITN.RowSource = ADOBind_Adodc3.DataSource
			Dim myDataCaptions As String() = {"Line", "Item", "Item Description", "Quantity", "Weight", "Unit price", "Price per", "Line amount", "Base Cur Amount", "Status"}
			Dim myDataFields As String() = {"ELOLN", "ELITN", "ELITD", "ELQTY", "ELWGT", "ELPRC", "ELPER", "ELAMT", "ELBCA", "ELSTT"}
			setDataGridView(myDataCaptions, myDataFields, Me.grdECL)
		End Sub

		Private Sub grdECL_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles grdECL.ClickEvent
			txtELOLN.Text = grdECL.Columns(1).value
			WriteToScreen()
			If SELECTROW = "" Then SELECTROW = 1
			Adodc4.Recordset.AbsolutePosition = SELECTROW
		End Sub

		Private Sub grdECL_RowColChange(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataGridLib.DDataGridEvents_RowColChangeEvent) Handles grdECL.RowColChange
			SELECTROW = Adodc4.Recordset.Bookmark
		End Sub

		Private Sub txtEHCCD_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCCD.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			Dim RecCCI As ADODB.Recordset
			If KeyAscii = 13 Then
				Result = Find("CCM", "CMCCD", "WHERE CMCCD='" & txtEHCCD.Text & "'")
				If Result <> "" Then
					RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtEHCCD.Text & "' order by CIDTE DESC")
					If Not RecCCI.EOF Then
						txtEHCER.Text = RecCCI.Fields("CICCR").Value
					Else
						txtEHCER.Text = CStr(0)
					End If
					txtEHCER.Focus()
				Else
					cboEHCCD.Visible = True
					cboEHCCD.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub txtEHCCD_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtEHCCD.Leave
			Dim Result As String
			Result = Find("CCM", "CMCCD", "WHERE CMCCD='" & txtEHCCD.Text & "'")
			Dim RecCCI As ADODB.Recordset
			If Result <> "" Then
				RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtEHCCD.Text & "' order by CIDTE DESC")
				If Not RecCCI.EOF Then
					txtEHCER.Text = RecCCI.Fields("CICCR").Value
				Else
					txtEHCER.Text = CStr(0)
				End If
				txtEHCER.Focus()
			Else
				cboEHCCD.Visible = True
				cboEHCCD.Focus()
			End If
		End Sub

		Private Sub txtEHCER_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCER.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELITN.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHCNO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCNO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("RCM", "CMNME", "WHERE CMCNO='" & txtEHCNO.Text & "'")
				If Result = "" Then
					cboEHCNO.Visible = True
					cboEHCNO.Focus()
				Else
					cboEHCNO.Visible = False
					txtCMNME.Text = Result
					txtEHSNO.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHCPO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCPO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCCD.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHDTE_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHDTE.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCNO.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHDUE_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHDUE.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCPO.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHODN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHODN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As Object
			If KeyAscii = 13 Then
				Result = Find("ECH", "EHODN", "WHERE EHODN='" & txtEHODN.Text & "'")
				If Result = "" Then
					txtEHDTE.Focus()
				Else
					MsgBox("Order Number is already exist")
					txtEHODN.Text = Result
					NewTrans = False
					ISADDING = False
					ISEDITING = False
					WriteToScreen()
					ButtonStatus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSNO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSNO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("SMM", "MMNME", "WHERE MMSNO='" & txtEHSNO.Text & "'")
				If Result = "" Then
					cboEHSNO.Visible = True
					cboEHSNO.Focus()
				Else
					cboEHSNO.Visible = False
					txtMMNME.Text = Result
					txtEHSTN.Focus()
				End If
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSTA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSTA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHDUE.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSTN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSTN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHSTA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELAMT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELAMT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELVAM.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELBCA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELBCA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELBVA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELBVA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELBVA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELAMT.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELITN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELITN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("IIM", "IMITD", "WHERE IMITN='" & txtELITN.Text & "'")
				If Result = "" Then
					cboELITN.Visible = True
					cboELITN.Focus()
				Else

					txtELITD.Text = Result
					txtELPRC.Text = Find("IIM", "IMPRC", "WHERE IMITN='" & txtELITN.Text & "'")
					cboELITN.Visible = False
					txtELVAT.Text = VATRate(txtEHCNO, txtELITN)
					txtELQTY.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
		Sub OpenFile()
			Dim DelStatus As Object
			Dim FieldDel As Object
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "Select * from RCM"
			Adodc1.Refresh()

			Adodc2.ConnectionString = ConnectString
			Adodc2.ConnectionTimeout = 10
			Adodc2.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc2.RecordSource = "Select * from AVM"
			Adodc2.Refresh()

			FieldDel = "IMRID"
			DelStatus = "IZ"
			SQL = "Select IMITN,IMITN +'  '+IMITD as IMITD  from IIM where " & FieldDel & " <>'" & DelStatus & "' "
			Adodc3.ConnectionString = ConnectString
			Adodc3.ConnectionTimeout = 10
			Adodc3.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc3.RecordSource = SQL
			Adodc3.Refresh()

			Adodc4.ConnectionString = ConnectString
			Adodc4.ConnectionTimeout = 10
			Adodc4.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' ORDER BY ELOLN"
			Adodc4.Refresh()

			Adodc5.ConnectionString = ConnectString
			Adodc5.ConnectionTimeout = 10
			Adodc5.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc5.RecordSource = "Select * from CCM"
			Adodc5.Refresh()

			Adodc6.ConnectionString = ConnectString
			Adodc6.ConnectionTimeout = 10
			Adodc6.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc6.RecordSource = "Select * from ECH"
			Adodc6.Refresh()

			Adodc7.ConnectionString = ConnectString
			Adodc7.ConnectionTimeout = 10
			Adodc7.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc7.RecordSource = "Select * from SMM"
			Adodc7.Refresh()

			' Create array from combobox Custtype,StatusOrder, ValuePer
			INVType(1) = "1 Normal"
			INVType(2) = "2 By pass Inventory"

			StaOrd(1) = "1 New"
			StaOrd(2) = "2 Printed"
			StaOrd(3) = "3 Confirmed"
			StaOrd(4) = "4 B/O"
			StaOrd(5) = "5 Caredit hold"
			StaOrd(6) = ""
			StaOrd(7) = "7 Canceled"
			Per(1) = "Unt"
			Per(2) = "Wgt"
			Per(3) = "All"
		End Sub

		Sub ButtonStatus()
			cmdReview.Enabled = Not ISEDITING
			CmdPreInvoice.Enabled = Not ISEDITING
			cmdEdit.Enabled = Not ISEDITING

			cmdSave.Enabled = ISEDITING
			cmdCancel.Enabled = ISEDITING

			FrameBB.Enabled = ISEDITING	'NewTrans
			FrameECLine.Enabled = ISEDITING
		End Sub

		Sub WriteToFile()
			Dim Unt As Object
			Dim WGT As Object
			Dim txtEHLDT As Object
			Dim txtELLDT As Object
			If Not Ktrastatus() Then
				Exit Sub
			End If
			Dim recECL As ADODB.Recordset

			If Not ValidInput() Then Exit Sub
			txtELLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")

			If NewTrans Then
				txtEHLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")
				txtEHDTE.Text = VB6.Format(WorkingDate, "dd/mm/yyyy")
				txtEHDUE.Text = VB6.Format(txtEHDUE.Text, "dd/mm/yyyy")

				SQL = "Insert into ECH (EHLDT,EHDTE,EHITP" & ",EHODN,EHCNO,EHSTN,EHPTC" & ",EHSTA,EHSNO,EHDUE,EHCPO" & ",EHCCD,EHCER,EHNOL,EHSTT,EHVAT) values " & "('" & txtEHLDT & "','" & VB6.Format(txtEHDTE.Text, "yyyy/mm/dd hh:mm:ss") & "','" & cboEHITP.SelectedIndex + 1 & "'" & ",'" & txtEHODN.Text & "','" & txtEHCNO.Text & "','" & txtEHSTN.Text & "','" & txtEHPTC.Text & "'" & ",'" & txtEHSTA.Text & "','" & txtEHSNO.Text & "','" & VB6.Format(txtEHDUE.Text, "yyyy/mm/dd hh:mm:ss") & "','" & txtEHCPO.Text & "'" & ",'" & txtEHCCD.Text & "'," & txtEHCER.Text & "," & txtEHNOL.Text & ",'1','" & txtELVAT.Text & "')"
				'MsgBox SQL
				DBconn.Execute(SQL)

			End If

			If ISADDING Then
				If txtELITN.Text <> "" Then
					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' order by ELOLN Desc ")
					If recECL.EOF Then
						txtELOLN.Text = CStr(1)
					Else
						txtELOLN.Text = recECL.Fields("ELOLN").Value + 1
					End If
					SQL = "Insert into ECL(ELODN,ELITN,ELITD,ELLUS" & ",ELPER,ELOLN,ELSTT " & ",ELQTY,ELWGT,ELPRC,ELPDC" & ",ELAMT,ELVAM,ELBCA,ELBVA,ELPSQ,ELPSW,ELVAT) values " & "('" & txtEHODN.Text & "','" & txtELITN.Text & "','" & txtELITD.Text & "','" & UserLogin & "'" & ",'" & cboELPER.SelectedIndex + 1 & "','" & txtELOLN.Text & "','1'" & "," & txtELQTY.Text & "," & txtELWGT.Text & "," & txtELPRC.Text & "," & txtELPDC.Text & "," & txtELAMT.Text & "," & txtELVAM.Text & "," & txtELBCA.Text & "," & txtELBVA.Text & "," & txtELPSQ.Text & "," & txtELPSW.Text & "," & txtELVAT.Text & ")"

					'MsgBox SQL
					DBconn.Execute(SQL)
					WriteToIIM(txtELITN, Val(txtELWGT.Text), Val(txtELQTY.Text))
				End If
			Else
				Select Case cboELPER.SelectedIndex + 1
					Case 1

						txtELBCA.Text = CStr(Val(txtELQTY.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)))
						txtELBVA.Text = CStr(Val(txtELBCA.Text) * Val(txtELVAT.Text))

						txtELAMT.Text = CStr(CInt(Val(txtELQTY.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)) * Val(txtEHCER.Text)))
						txtELVAM.Text = CStr(CInt(Val(txtELAMT.Text) * Val(txtELVAT.Text)))

					Case 2

						txtELBCA.Text = CStr(Val(txtELWGT.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)))
						txtELBVA.Text = CStr(Val(txtELBCA.Text) * Val(txtELVAT.Text))

						txtELAMT.Text = CStr(CInt(Val(txtELWGT.Text) * (Val(txtELPRC.Text) - (Val(txtELPRC.Text) * Val(txtELPDC.Text) / 100)) * Val(txtEHCER.Text))) '+ Val(txtELVAM)
						txtELVAM.Text = CStr(CInt(Val(txtELAMT.Text) * Val(txtELVAT.Text)))
				End Select
				txtEHLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")
				txtEHDTE.Text = VB6.Format(txtEHDTE.Text, "dd/mm/yyyy")
				txtEHDUE.Text = VB6.Format(txtEHDUE.Text, "dd/mm/yyyy")
				'///////////////////////////////////////////////////////
				' Xet trang thai invoice status
				'/////////////////////////////////////////////
				If VB.Left(VB6.GetItemString(cboEHSTT, cboEHSTT.SelectedIndex), 1) = "7" Then 'Cancel

					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' AND ELSTT<>'7'")
					With recECL
						Do While Not recECL.EOF
							WGT = -(.Fields("ELWGT")).Value
							Unt = -(.Fields("ELQTY")).Value
							WriteToIIM(.Fields("ELITN"), WGT, Unt)
							recECL.MoveNext()
						Loop
					End With
					SQL = "Update ECL  set ELSTT='7' where ELODN='" & txtEHODN.Text & "'"
					DBconn.Execute(SQL)
				Else ' Khac cancel
					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
					With recECL
						If VB.Left(VB6.GetItemString(cboELSTT, cboELSTT.SelectedIndex), 1) = "7" Then 'Cancel
							Unt = -(.Fields("ELQTY")).Value
							WGT = -(.Fields("ELWGT")).Value
						Else
							Unt = Val(txtELQTY.Text) - .Fields("ELQTY").Value
							WGT = Val(txtELWGT.Text) - .Fields("ELWGT").Value
						End If
					End With
					WriteToIIM(txtELITN, WGT, Unt)
				End If ' Ket thuc xet trang thai invoice

				SQL = "Update ECL set ELLDT='" & txtELLDT & "',ELITN='" & txtELITN.Text & "',ELITD='" & txtELITD.Text & "',ELLUS='" & UserLogin & "'" & ",ELPER='" & cboELPER.SelectedIndex + 1 & "',ELOLN='" & txtELOLN.Text & "',ELSTT='" & cboELSTT.SelectedIndex + 1 & "'" & ",ELQTY=" & txtELQTY.Text & ",ELPSQ=" & txtELPSQ.Text & ",ELWGT=" & txtELWGT.Text & ",ELPSW=" & txtELPSW.Text & ",ELPRC=" & txtELPRC.Text & ",ELPDC=" & txtELPDC.Text & ",ELAMT=" & txtELAMT.Text & ",ELVAM=" & txtELVAM.Text & ",ELBCA=" & txtELBCA.Text & ",ELBVA=" & txtELBVA.Text & ",ELVAT=" & txtELVAT.Text & " where ELODN='" & OldEHODN & "' AND ELOLN='" & txtELOLN.Text & "'"
				DBconn.Execute(SQL)


				SQL = "Update ECH set EHLDT='" & txtEHLDT & "',EHDTE='" & VB6.Format(txtEHDTE.Text, "yyyy/mm/dd hh:mm:ss") & "',EHITP='" & cboEHITP.SelectedIndex + 1 & "'" & ",EHODN='" & txtEHODN.Text & "',EHCNO='" & txtEHCNO.Text & "',EHSTN='" & txtEHSTN.Text & "',EHPTC='" & txtEHPTC.Text & "'" & ",EHSTA='" & txtEHSTA.Text & "',EHSNO='" & txtEHSNO.Text & "',EHDUE='" & VB6.Format(txtEHDUE.Text, "yyyy/mm/dd hh:mm:ss") & "',EHCPO='" & txtEHCPO.Text & "'" & ",EHCCD='" & txtEHCCD.Text & "',EHCER=" & txtEHCER.Text & ",EHVAT=" & txtELVAT.Text & " where EHODN='" & OldEHODN & "'"
				DBconn.Execute(SQL)
			End If
			Dim RecCountLine As ADODB.Recordset
			RecCountLine = DBconn.Execute("SELECT ELODN, COUNT(ELOLN) AS CountLine From ECL " & " WHERE (ELODN = '" & txtEHODN.Text & "') AND (ELSTT <> N'7')GROUP BY ELODN")
			txtEHNOL.Text = RecCountLine.Fields("CountLine").Value
			RecCountLine.Close()

			recECL.Close()
			recECL = DBconn.Execute("SELECT ELODN, SUM(ELVAM) AS SumELVAM, SUM(ELAMT)" & " AS SumELAMT, SUM(ELBVA) AS SumELBVA, SUM(ELBCA) " & " AS SumELBCA FROM ECL WHERE (ELODN = '" & txtEHODN.Text & "') GROUP BY ELODN")
			With recECL
				txtEHAMT.Text = .Fields("SumELAMT").Value
				txtEHVAM.Text = .Fields("SumELVAM").Value
				txtEHBCA.Text = .Fields("SumELBCA").Value
				txtEHBVA.Text = .Fields("SumELBVA").Value
			End With
			recECL.Close()

			DBconn.Execute("UPDATE ECH SET EHAMT=" & txtEHAMT.Text & ",EHVAM=" & txtEHVAM.Text & ",EHBAM=" & txtEHBCA.Text & ",EHBVA=" & txtEHBVA.Text & " WHERE EHODN='" & txtEHODN.Text & "'")

			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' ORDER BY ELOLN"
			Adodc4.Refresh()
			NewTrans = False
			ISADDING = False
			ISEDITING = False
			ButtonStatus()
		End Sub

		Sub WriteToIIM(ByRef ITN As Object, ByRef WGT As Object, ByRef unit As Object)

			unit = IIf(IsNumeric(unit), unit, 0)
			WGT = IIf(IsNumeric(WGT), WGT, 0)


			SQL = "UPDATE IIM SET IMCOW=IMCOW+" & WGT & ",IMCOU=IMCOU+" & unit & " WHERE IMITN='" & ITN & "'"
			DBconn.Execute(SQL)

		End Sub


		Private Sub txtELPDC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELPDC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELPRC.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELPRC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELPRC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				If cboELPER.Text <> "" Then
					Call UpdateAmt()
				Else
					cboELPER.Focus()
				End If
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub



		Private Sub txtELPRC_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtELPRC.Leave

			If cboELPER.Text <> "" And txtELPRC.Text <> "" Then
				Call UpdateAmt()
			Else
				cboELPER.Focus()
			End If
		End Sub

		Private Sub txtELPSQ_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELPSQ.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim RecIIM As ADODB.Recordset
			If KeyAscii = 13 Then
				txtELWGT.Focus()
				RecIIM = DBconn.Execute("Select IMWPU from IIM where IMITN='" & txtELITN.Text & "'")
				If Not RecIIM.EOF Then
					If IsDBNull(RecIIM.Fields("IMWPU").Value) Then
						txtELPSW.Text = ""
						txtELPSW.Focus()
					Else
						txtELPSW.Text = CStr(RecIIM.Fields("IMWPU").Value * CDbl(txtELPSQ.Text))
					End If

				Else
					txtELPSW.Text = CStr(0)
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELQTY_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELQTY.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim RecIIM As ADODB.Recordset
			If KeyAscii = 13 Then
				txtELWGT.Focus()
				RecIIM = DBconn.Execute("Select IMWPU from IIM where IMITN='" & txtELITN.Text & "'")
				If Not RecIIM.EOF Then
					If IsDBNull(RecIIM.Fields("IMWPU").Value) Then
						txtELWGT.Text = ""
						txtELWGT.Focus()
					Else
						txtELWGT.Text = CStr(RecIIM.Fields("IMWPU").Value * CDbl(txtELQTY.Text))
						txtELPSQ.Focus()
					End If
				Else
					txtELWGT.Text = CStr(0)
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELVAM_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELVAM.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then cmdSave.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELVAT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELVAT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELBCA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELWGT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELWGT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELPDC.Focus()

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
		Sub tam()
			Dim Unt As Object
			Dim WGT As Object
			Dim recECL As Object
			If VB.Left(VB6.GetItemString(cboEHSTT, cboEHSTT.SelectedIndex), 1) = "7" Then 'Cancel
				SQL = "Update ECL  set ELSTT='7' where ELODN='" & txtEHODN.Text & "'"
				DBconn.Execute(SQL)

				recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "'")
				With recECL
					Do While Not recECL.EOF
						WGT = -(!ELWGT)
						Unt = -(!ELQTY)
						WriteToIIM(!ELITN, WGT, Unt)
						recECL.MoveNext()
					Loop
				End With
			Else
				recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
				With recECL
					If VB.Left(VB6.GetItemString(cboELSTT, cboELSTT.SelectedIndex), 1) = "7" Then 'Cancel
						Unt = -(recECL!ELQTY)
						WGT = -(recECL!ELWGT)
					Else
						Unt = recECL!ELQTY - Val(txtELQTY.Text)
						WGT = recECL!ELWGT - Val(txtELWGT.Text)
					End If
				End With
				WriteToIIM(txtELITN, WGT, Unt)
			End If
		End Sub

		Function ValidInput() As Object
			Dim Result As Object
			Dim StrErr As String
			Dim Havelot As Byte
			Havelot = False
			If Not IsDate(txtEHDTE.Text) Then StrErr = StrErr & Chr(13) & "* Wrong Invoice Date!"
			If Not IsDate(txtEHDUE.Text) Then StrErr = StrErr & Chr(13) & "* Wrong Due Date!"
			If Find("RCM", "CMCNO", "WHERE CMCNO='" & txtEHCNO.Text & "'") = "" Then StrErr = StrErr & Chr(13) & "* Not have Customer"

			If Find("CCM", "CMCCD", "WHERE CMCCD='" & txtEHCCD.Text & "'") = "" Then StrErr = StrErr & Chr(13) & "* Not have Currency code"


			If CDbl(txtELQTY.Text) = 0 Then StrErr = StrErr & Chr(13) & "* Quantity must be >0"
			If CDbl(txtELWGT.Text) = 0 Then StrErr = StrErr & Chr(13) & "* Weight must be >0"
			If StrErr <> "" Then
				MsgBox("Please check again!" & StrErr)
				ValidInput = False
			Else
				ValidInput = True
			End If
		End Function


		Private Function Ktrastatus() As Boolean
			Ktrastatus = True
			If (txtELQTY.Text = "" Or txtELPSQ.Text = "" Or txtELWGT.Text = "" Or txtELPSW.Text = "") Then
				MsgBox("One of Quantity, Weight must be have value")
				Ktrastatus = False
			ElseIf (txtEHCER.Text = "" Or txtEHCCD.Text = "" Or txtELPDC.Text = "" Or txtELVAT.Text = "" Or txtELPRC.Text = "") Then
				MsgBox("One of Current code,Exchange rate, Discount,Price per, Vat must be have value")
				Ktrastatus = False
			ElseIf txtELITN.Text = "" Or txtELITD.Text = "" Then
				MsgBox("One of Item, Item description must be have value")
				Ktrastatus = False
			End If

		End Function
	End Class
End Namespace